package com.hyj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hyj.entity.Memberships;
import com.hyj.entity.Students;
import com.hyj.service.MemService;
import com.hyj.service.StuService;
import com.hyj.utils.Result;

@RestController
public class MembershipsController {
	@Autowired
	private MemService memService;
	
	@Autowired
	StuService stuService;
	/**
	 * 全查学历
	 * @param Education
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getMem")
	public Object getMem(Memberships mem) {
		List<Memberships> list = memService.getMem(mem);
		mem.setPage(null);
		mem.setLimit(null);

		System.out.println("查得到学历全部数据" + list);
		List<Memberships> list2 = memService.getMem(mem);

		return  new Result(0,"",list2.size(),list);
	}
	/**
	 * 添加学历方法
	 * @param e
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addMem")
	public Object addMem(Memberships e,Memberships Specialty) {
		List<Memberships> list = memService.getMem(Specialty);
		
		Map<String, Object> map = new HashMap<String, Object>();
			if (null==list||list.size()==0) {
				boolean mem = memService.addMem(e);
				if (mem) {
					map.put("code", "0");
					map.put("msg", "添加成功！！！");
				}else {
					map.put("code", "1");
					map.put("msg", "添加失败！！！");					
				}
				System.out.println("拿到的添加的学历数据" + mem);
			}
		return map;
	}
	/**
	 * 删除学历方法
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delMem")
	public Object delMem (Integer MId) {
		System.out.println("拿到删除学历ID:"+MId);
		List<Students> list=stuService.getStu(null);
		System.out.println("拿到删除学历List:"+list);
		Map<String,Object> map = new HashMap<String,Object>();
		if (null==list||list.size()==0) {
			boolean mem = memService.delMem(MId);
			if (mem) {
				map.put("code", "0");
				map.put("msg", "删除成功！！！");
			}else {
				map.put("code", "1");
				map.put("msg", "删除失败！！！");
				
			}
		}else {
			map.put("code", "2");
			map.put("msg", "该专业下有学生，删除失败！！");
		}
		return map;
	}
	/**
	 * 修改学历方法
	 * @param 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateMem")
	public Object updateMem(Memberships MId) {
		int mem =memService.updateMem(MId);
		System.out.println("拿到修改学历信息的数据："+MId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "学历修改");
		map.put("count", 100); 
		map.put("data", mem); 
		return map;
	}
	
	
	
	
}
